﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

using Telerik.WinControls;

namespace UnigenReport
{
    public partial class fQuery : Telerik.WinControls.UI.RadForm
    {

        #region Thiết lập

        public fQuery()
        {
            InitializeComponent();

            SetEvent();
        }

        /// <summary>
        /// Khai báo các sự kiện
        /// </summary>
        private void SetEvent()
        {           
            btnSave.Click += btnSave_Click;
        }

        #endregion

        #region Hàm
        
        /// <summary>
        /// Lưu thông số cấu hình
        /// </summary>
        public void SaveConfig()
        {
            try
            {
                var query = txtQuery.Text.Trim();
                var db = new UnigenDataContext();
                db.ExecuteCommand(query);
                Common.ShowDoneMess("Done!");
            }
            catch (Exception ex)
            {
                Common.ShowErrorMess("SaveConfig - " + ex.Message);
            }
        }        
        #endregion

        #region Sự kiện

        private void btnSave_Click(object sender, EventArgs e)
        {
            if(Common.ShowQuestion("Sure?") == System.Windows.Forms.DialogResult.OK)
                SaveConfig();
        }

        #endregion

    }
}
